package com.googlecode.jcaffe.control.modules.mainwindow;

import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public final class MainWindow {
	private MainWindowView view;
	private MainWindowModel model;
	@SuppressWarnings("unused")
	private MainWindowController controller;

	public MainWindow() {
		MainWindowView.setDefaultLookAndFeelDecorated(true);

		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}
		catch (ClassNotFoundException e) {
			JOptionPane.showMessageDialog(null, "Class, which supports system look and feel, has not been found.", "Error", JOptionPane.ERROR_MESSAGE);
		}
		catch (InstantiationException e) {
			JOptionPane.showMessageDialog(null, "Can not initialize class.", "Error", JOptionPane.ERROR_MESSAGE);
		}
		catch (IllegalAccessException e) {
			JOptionPane.showMessageDialog(null, "Illegal access.", "Error", JOptionPane.ERROR_MESSAGE);
		}
		catch (UnsupportedLookAndFeelException e) {
			JOptionPane.showMessageDialog(null, "Unsuported platform look and feel.", "Error", JOptionPane.ERROR_MESSAGE);
		}

		view = new MainWindowView();
		model = new MainWindowModel();
		// In MVC design, a link between Model and Controller, View and
		// Controller must exist in order to separate GUI from logic.
		controller = new MainWindowController(view, model);
	}

	public void showWindow(boolean state) {
		view.setVisible(state);
	}
}
